package com.android.jixin.channel.base;

import android.app.Application;
import android.os.StrictMode;

import com.android.jixin.channel.injector.component.ApplicationComponent;
import com.android.jixin.channel.injector.component.DaggerApplicationComponent;
import com.android.jixin.channel.injector.module.ApplicationModule;
import com.rey.material.app.ThemeManager;

import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.GINGERBREAD;

/**
 * Author:  jact
 * Date:    2016/3/16
 * Description:
 */
public class AppApplication extends Application {

    private ApplicationComponent component;
    /*private RefWatcher refWatcher;

    public static RefWatcher getRefWatcher(Context context) {
        AppApplication application = (AppApplication) context
                .getApplicationContext();
        return application.refWatcher;
    }*/

    @Override
    public void onCreate() {
        super.onCreate();
        ThemeManager.init(this, 2, 0, null);
        init();
    }

    private void init(){
        initDb();


        this.component = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .build();
        this.component.injectApplication(this);

        enabledStrictMode();
        //refWatcher = LeakCanary.install(this);
    }

    private void initDb(){
        //DaoManager.init(this);
    }

    private void enabledStrictMode() {
        if (SDK_INT >= GINGERBREAD) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() //
                    .detectAll() //
                    .penaltyLog() //
                    .penaltyDeath() //
                    .build());
        }
    }

    public ApplicationComponent getApplicationComponent() {
        return this.component;
    }

}
